/*
 * Copyright (C) 2009 Teleca Poland Sp. z o.o. <android@teleca.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uneed.adapter;

import java.text.SimpleDateFormat;

import com.uneed.R;
import com.uneed.api.Review;
import com.uneed.api.Shop;
import com.uneed.widget.RemoteImageView;

import android.R.integer;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

/**
 * Adapter representing albums
 * 
 * @author Lukasz Wisniewski
 */
public class ReviewAdapter extends ArrayListAdapter<Review> {
	
	  static final SimpleDateFormat FMT = new SimpleDateFormat("yy-MM-dd HH:mm");

	
	public ReviewAdapter(Activity context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row=convertView;

		ViewHolder holder;

		if (row==null) {
			LayoutInflater inflater = mContext.getLayoutInflater();
			row=inflater.inflate(R.layout.review_item_in_shopinfo, null);

			holder = new ViewHolder();
//			holder.username = (RemoteImageView)row.findViewById(R.id.shopImageView);
			holder.username = (TextView)row.findViewById(android.R.id.text1);
			holder.content = (TextView)row.findViewById(android.R.id.text2);
//			holder.progressBar = (ProgressBar)row.findViewById(R.id.AlbumRowRatingBar);
			holder.time = (TextView)row.findViewById(R.id.text4);
//			holder.description = (TextView)row.findViewById(R.id.shopdesc);
		
			row.setTag(holder);
		}
		else{
			holder = (ViewHolder) row.getTag();
		}
		
//		holder.image.setDefaultImage(R.drawable.placeholder_loading);
//		holder.image.setEmptyImage(R.drawable.placeholder_empty);
//		holder.image.setImageUrl(mList.get(position).getThumb(),position, getListView());
		holder.username.setText(mList.get(position).getUsername());
		holder.content.setText(mList.get(position).getContent());
		holder.time.setText(FMT.format(mList.get(position).getTime()));

		//		holder.progressBar.setMax(10);
//		holder.progressBar.setProgress((int) (mList.get(position).getRating()*10));

		return row;
	}
	
	/**
	 * Class implementing holder pattern,
	 * performance boost
	 * 
	 * @author Lukasz Wisniewski
	 */
	static class ViewHolder {

//		RemoteImageView image;
		TextView username;
		TextView content;
//		ProgressBar progressBar;
		TextView time;
//		TextView description;
	}
}
